<!--
缴费名单详情
-->
<template>
  <div class="app-container">
    <el-row :gutter="10">
      <!-- 学生 -->
      <el-col :span="8">
        <el-card style="height: calc(100vh - 125px)">
          <div slot="header">
            <span><i class="el-icon-document"></i> 缴费学生</span>
            <el-col :span="1.5">
              <el-button
                type="primary"
                plain
                icon="el-icon-s-promotion"
                size="mini"
                @click="handleRelease"
                v-hasPermi="['uniquefees:stu_book:release']"
              >发布
              </el-button>
            </el-col>

            <el-col :span="1.5" v-if="false">
              <el-button
                type="danger"
                plain
                icon="el-icon-refresh-left"
                size="mini"
                @click="handleRevokeRelease"
                v-hasPermi="['uniquefees:stu_book:release']"
              >撤回发布
              </el-button>
            </el-col>
          </div>
          <el-table
            ref="itemTable"
            v-loading="itemLoading"
            :data="students"
            :height="tableHeight"
            highlight-current-row
            style="width: 100%"
            :row-key="getItemRowKey"
            @row-click="clickRow"
            @selection-change="handleSelectionChange"
          >
            <el-table-column type="selection" :selectable="selectableRow" :reserve-selection="true"
                             width="55"></el-table-column>
            <el-table-column label="序号" width="60" type="index"></el-table-column>
            <el-table-column label="姓名" align="center" prop="studentName"
                             :show-overflow-tooltip="true"></el-table-column>
            <el-table-column label="金额" align="center" prop="totalPrice"
                             :show-overflow-tooltip="true"></el-table-column>
          </el-table>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script>


import {deptStuBook, releaseStuList, revokeReleaseStu_book} from "@/api/uniquefees/stu_book";
import {listStudentsByDeptId} from "@/api/campus/students";

export default {
  props: {
    value: [String, Object, Array]
  },
  name: "Stu_List",
  components: {},
  dicts: ['sys_normal_disable', 'semester'],
  data() {
    return {
      students: [],
      selectedItems: [], // 包含选中项的唯一标识数组
      // 总条数
      total: 0,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        semesterYear: null,
        semester: null,
        deptId: null,
        status: null,
        delFlag: null,
        sysOrgCode: null,
        code: null,
        name: null,
        school: null,
        college: null,
        major: null,
        clazz: null,
        grade: null,
        collegeId: null,
        schoolId: null,
        majorId: null,
        clazzId: null,
        headteacher: null,
        headteacherTel: null,
        headstudent: null,
        headstudentTel: null,
        issuanceDate: null,
        other: null,
        schoolYear: null,
        pricesum: null,
        booklistPic: null,
        bookListDetail: null
      },
      // 遮罩层
      itemLoading: false,
      tableHeight: window.innerHeight - 200
    };
  },
  created() {
    // this.getStudents()
  },
  watch: {
    value: {
      handler(newValue, oldValue) {
        if (newValue && newValue !== oldValue) {
          this.queryParams.scheduleId = newValue.id;
          this.queryParams.deptId = newValue.deptId;
          this.getStudents();
        } else {
          this.queryParams.scheduleId = null;
        }
      },
      deep: true,
      immediate: true
    }
  },
  methods: {
    /** 查询缴费清单列表 */
    getStudents() {
      this.loading = true;
      if (this.queryParams.deptId) {
        listStudentsByDeptId(this.queryParams.deptId).then(response => {
          this.students = response.data;
          this.itemLoading = false;
        });
      }
    },
    /** 单击选中行数据 */
    clickRow(row) {
      if (this.openItemEdit) {
        this.$refs.itemTable.toggleRowSelection(row);
      }

    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.selectedItems = selection.map((item) => item.courseId);
    },
    handleUpdateOpen() {
      this.openItemEdit = !this.openItemEdit;
    },
    selectableRow(row, index) {
      // 根据 selectAllRows 的值决定是否允许选择所有行
      return this.openItemEdit;
    },
    // 保存选中的数据编号
    getItemRowKey(row) {
      return row.courseId;
    },
    /**
     * 查询缴费学生
     * @param row
     */
    getPayStu(row) {
      this.payStuItem = []
      const queryParams = {
        deptId: null,
        scheduleId: row.id,
        semesterYear: null,
        semester: null
      }
      this.subLoading = true;
      deptStuBook(queryParams).then(response => {
        this.payStu = response.data.courseStu;
        this.subLoading = false;
      });
    },
    /** 发布按钮操作 */
    handleRelease() {
      releaseStuList(this.value).then(response => {
        this.$modal.msgSuccess("发布成功！");
      });
    },
    /** 撤回发布发布按钮操作 */
    handleRevokeRelease() {
      const data = {
        scheduleId: this.queryParams.scheduleId,
        stuBooks: this.stu_bookList,
        courseBooks: this.books,
        orderName: this.orderTitle,
      }
      revokeReleaseStu_book(data).then(response => {
        this.$modal.msgSuccess("发布成功！");
      });
    }
  }
};
</script>
